import * as types from './constans'
import { reqSongDetail } from '@/api/song'
export const changeIsExpandSlider = (status) => {
    return dispatch => {
        dispatch({
            type: types.CHANGE_IS_EXPAND_SLIDER,
            payload: status
        })
    }
}
const changeCurSong = (song) => ({
    type: types.CHANGE_CUR_SONG,
    payload: song
})
const changePlayList = (list) => ({
    type: types.CHANGE_PLAY_LIST,
    payload: list
})

export const changePlaying = (flag) => ({
    type: types.CHANGE_PLAY_ING,
    payload: flag
})
export const getCurSong = (id) => {
    return (dispatch, getState) => {
        const playList = getState().getIn(['playList']);
        const song = playList.find(v => v.id === id)
        if (song) {
            dispatch(changeCurSong(song))
            return
        }
        reqSongDetail(id).then(res => {
            if (res.code === 200) {
                const song = res.songs[0];
                dispatch(changeCurSong(song))
                playList.unshift(song)
                dispatch(changePlayList(playList))
            }
        })
    }
}
